package com.atguigu.condition;

import com.atguigu.bean.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author:zwy
 * @Despriction:
 * @Date:Create in 15:11 2018/7/7
 * @Modify By:
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     *
     * @param importingClassMetadata 当前类的注解信息
     * @param registry  BeanDefinition注册类
     *                  把所有需要添加到容器中的bean:BeanDefinitionRegistry.registerBeanDefinitions
     *                  手工注册
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean red = registry.containsBeanDefinition("com.atguigu.bean.Red");
        boolean blue = registry.containsBeanDefinition("com.atguigu.bean.Blue");
        if(red&&blue){
            //指定Bean定义信息:(Bean类型等待。。。)
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(RainBow.class);
            //指定bean名
            registry.registerBeanDefinition("rainBow",rootBeanDefinition);
        }
    }
}
